package com.qf.blogsystem.core.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import java.util.Properties;

/**
 * @author Crazy
 * @version 1.0
 * @description: 连接池工具类
 * @date 2022/11/23 20:47
 */
public class DruidUtils {
    /**
     * 声明连接池对象
     */
    private static DruidDataSource dataSource = null;

    static {
        //加载配置文件
        Properties p = new Properties();
        try {
            p.load(DruidUtils.class.getClassLoader().getResourceAsStream("Jdbc.properties"));
            //获得连接池对象
            dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(p);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static DruidDataSource getDataSource() {
        return dataSource;
    }

    public static void setDataSource(DruidDataSource dataSource) {
        DruidUtils.dataSource = dataSource;
    }
}
